var express = require('express');
var router = express.Router();
var retUtil = require('../util/retUtil');
var usersUtil = require('./util/usersUtil');

router.get('/ck', function(req, res, next) {
    res.json({'ok':':)'});
});

//################################################################################
/**
 * 中台系统账号密码登录
 * @author xc
 * @date 2018-07-09
 *
 * @param account  用户名
 * @param password 密码(经过MD5加密)
 *
 * 参考: http://yapi.yijianxiu.com:7000/mock/34/yjx/v1/api4back/users/middleStageLogin
 */
function middleStageLogin(req, res, next) {
    res.header("Access-Control-Allow-Origin", "*");   //设置跨域访问

    var account = retUtil.stringFromReq(req, 'account') || '';
    var password = retUtil.stringFromReq(req, 'password') || '';

    if(!account || account.length==0 || !password || password.length==0) {
        return retUtil.ret_err_json("参数有误",res)
    }

    // 参数信息
    var param = {
        account : account,
        password : password,
        orgTypes: [100,300,400,410]
    };
    usersUtil.midStageLogin(param,function (error, data) {
        if(error) {
            return retUtil.ret_err_json(error, res);
        }
        return retUtil.ret_succ_json(data, res);
    });
}
router.get('/middleStageLogin', middleStageLogin);
router.post('/middleStageLogin', middleStageLogin);


module.exports = router;
